<template>
  <div id="dog-contain">
    <img :src="img" alt="" />
    <p :style="{ backgroundColor: iscolor }" @click="btn">{{ name }}</p>
  </div>
</template>

<script>
export default {
  name: 'Dog',
  props: ['name', 'img'],
  data () {
    return {
      colorStr: '',
      flag: true,
      iscolor: ''
    }
  },
  created () {},
  methods: {
    btn () {
      if (this.flag) {
        this.$emit('addLike', this.name)
        this.iscolor = `rgb(${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)})`
        this.flag = !this.flag
      } else {
        this.$emit('subLike', this.name)
        this.iscolor = ''
        this.flag = !this.flag
      }
    }
  }
}
</script>

<style lang='less' scoped>
#dog-contain {
  width: 200px;
  border: 1px solid black;
  text-align: center;
  float: left;
}
#dog-contain img {
  width: 100%;
  height: 200px;
}
</style>
